﻿using Infrastructure.Extend;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;

namespace Domain.Model.ValueObject
{
    ///<summary>
    /// MiniUI控件可传参数
    /// </summary>
    [Serializable]
    public class MiniUIParams
    {

        #region 方法
        /// <summary>
        /// 当前页数
        /// </summary>
        public int PageIndex { get; set; }

        /// <summary>
        /// 页面大小
        /// </summary>
        public int PageSize { get; set; }

        /// <summary>
        /// 排序字段
        /// </summary>
        public string SortField { get; set; }

        /// <summary>
        /// 排序方式
        /// </summary>
        public string SortOrder { get; set; }

        /// <summary>
        /// 搜索关键字
        /// </summary>
        public string Key { get; set; }  

        /// <summary>
        /// 获取搜索关键字安全类型
        /// </summary>
        public string SafeKeyword
        {
            get
            {
                return Regex.Replace(this.Key.NullThenEmpty(), @"[-|;|,|\/|\(|\)|\[|\]|\}|\{|%|@|\*|!|\']", string.Empty);
            }
        }

        /// <summary>
        /// 转换为OrderByString
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            if (!string.IsNullOrEmpty(this.SortField) && !string.IsNullOrEmpty(this.SortOrder))
            {
                return string.Format("{0} {1}", this.SortField, this.SortOrder);
            }
            return string.Format("{0} {1}", "CreateTime", "desc");
        }

        #endregion


        ///// <summary>
        ///// 获取搜索关键字安全类型
        ///// </summary>
        //public string SafeKeyword
        //{
        //    get
        //    {
        //        return Regex.Replace(this.key.NullThenEmpty(), @"[-|;|,|\/|\(|\)|\[|\]|\}|\{|%|@|\*|!|\']", string.Empty);
        //    }
        //}




    }


}